//
//  FilmViewController.m
//  UI12豆瓣大项目
//
//  Created by dllo on 15/10/26.
//  Copyright (c) 2015年 蓝鸥科技. All rights reserved.
//
#define WIDTH  [[UIScreen mainScreen] bounds].size.width
#define HEIGHT [[UIScreen mainScreen] bounds].size.height


#import "FilmViewController.h"
#import "FilmTableViewCell.h"
#import "AppTools.h"
#import "Activity.h"
#import "FilmDetailViewController.h"
#import "NineViewController.h"

@interface FilmViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,retain) NineViewController *nineVC;
@property (nonatomic,copy) NSString *filmPath;
@end

@implementation FilmViewController
- (void)dealloc
{
    [_nineVC release];
    [_filmArray release];
    [_fileTableView release];
    [super dealloc];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    self.fileTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT - 64 -49)];
    self.fileTableView.delegate = self;
    self.fileTableView.dataSource = self;
    [self.view addSubview:self.fileTableView];
    [_fileTableView release];
    
    [self.fileTableView registerClass:[FilmTableViewCell class] forCellReuseIdentifier:@"cell"];
    [self getAFNData];
//    //创建路径
//    self.filmPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, nil) lastObject] stringByAppendingPathComponent:@"activity.xml"];
//    //查找
//    self.filmArray =
    
    
    // Do any additional setup after loading the view.
}


-(void)getAFNData{
    //加载菊花
    self.hub = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self.hub show:YES];
    self.hub.labelText = @"请耐心等待....";
    //请求网络
    [AppTools getDataWithkey:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/movielist.php" block:^(id result) {
        //        NSLog(@"%@",result);
        NSMutableDictionary *bigDic = result;
        NSString *error_code = [bigDic objectForKey:@"error_code"];
        NSString *reason = [bigDic objectForKey:@"reason"];
        NSMutableArray *array = [bigDic objectForKey:@"result"];
        if ([reason isEqualToString:@"success"]) {
            self.filmArray = [NSMutableArray array];
            for (NSMutableDictionary *dic in array) {
                Activity *activity = [[Activity alloc] init];
                [activity setValuesForKeysWithDictionary:dic];
                [self.filmArray addObject:activity];
                
                [activity release];
            }
            [self.fileTableView reloadData];
            [self.hub hide:YES];
        }else{
            NSLog(@"请求失败");
        }
    }];
}



-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.filmArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellI = @"cell";
    FilmTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellI];
//        cell.textLabel.text = @"da";
    Activity *activity = [self.filmArray objectAtIndex:indexPath.row];
    cell.activiy = activity;
    return cell;
}



-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 150;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    Activity *activity = [self.filmArray objectAtIndex:indexPath.row];
    FilmDetailViewController *filmDVC = [[FilmDetailViewController alloc] init];
    filmDVC.movieID = activity.movieId;
    [self.navigationController pushViewController:filmDVC animated:YES];
    [filmDVC release];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
